<?php

namespace app\admin\controller;

use app\common\controller\AdminController;

//引入外部函数
use app\common\model\hfztcy\LibEvaluation;


/**
 * 评价管理
 * @name Evaluate.php
 * @package hfztcy
 * @category controller
 * @author rxy
 * @version 1.0
 * @copyright CHANGE INC
 * @since 2020-6-5
 */
class Evaluate extends AdminController
{
    protected $model;

    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new LibEvaluation();
        $this->rightVerify(session('admin'), url("admin/Login/login"));
        parent::__construct();
    }

    /**
     * 列表页
     */
    function evaluateList()
    {
        $this->getSetMenu($this);
        $this->log(__CLASS__, __FUNCTION__, "列表页", 1, 'view');
        return $this->fetch('Evaluate/evaluateList/evaluateList');
    }

    /**
     * 详情页面
     */
    function detailEvaluate()
    {
        $this->getMenu($this);
        $evaluateInfo = $this->model->findEvaluation(['id' => input("id")]);
        $evaluateInfo = $evaluateInfo['data'];
        $this->assign('evaluateInfo', $evaluateInfo);
        $this->log(__CLASS__, __FUNCTION__, "详情页面", 1, 'view');
        return $this->fetch('Evaluate/detailEvaluate/detailEvaluate');
    }

    /**
     * 编辑页面
     */
    function editEvaluate()
    {
        $this->getMenu($this);
        $evaluateInfo = $this->model->findEvaluation(['id' => input("id")]);
        $this->assign('evaluateInfo', $evaluateInfo['data']);
        $this->log(__CLASS__, __FUNCTION__, "编辑页面", 1, 'view');
        return $this->fetch('Evaluate/editEvaluate/editEvaluate');
    }

    /**
     * 删除
     */
    function deleteEvaluate()
    {
        $id = input("id");
        $result = $this->model->deleteEvaluation(["id" => $id]);
        echo json_encode($result);
    }

    /**
     * 分页查询
     */
    function pagingEvaluate()
    {
        $args = $this->getArgsList($this, ['user_id', 'username','state']);
        $page = $this->getPageInfo();
        $where = [];
        //$where[] = "FIND_IN_SET({$args['state']},identity)";
        if ($args['state'] == 3) {//红娘
            $where[] = "`type` = 0";
        } else {//门店
            $where[] = "`type` = 1";
        }
        if (!empty($args['user_id'])) $where[] = "`user_id` = " . $args['user_id'];
        if (!empty($args['username'])) $where[] = "`username` = '" . $args['username'] . "'";
        $result = $this->model->pagingEvaluation($page, implode(' AND ', $where));
        foreach ($result['data']['dataList'] as &$item) {
            $item['first_img'] = '';
            if (!empty($item['img'])) {
                $arr = explode(',',$item['img']);
                $item['first_img'] = $arr[0];
            }
        }
        echo json_encode($result);
    }
}

?>